x86/irq: do not release irq until all cleanup is done
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 20 Dec 2022 12:43:04 +0000 (13:43 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 20 Dec 2022 12:43:04 +0000 (13:43 +0100)
commit9cbc04a95f8a7f7cc27901211cbe19a42850c4ed
treeb0ac95fc7bf539a317b33ff4f2ec2836603bfcd3
parent0b999fa2eadaeff840a8331b87f1f73abf3b14eb
x86/irq: do not release irq until all cleanup is done

Current code in _clear_irq_vector() will mark the irq as unused before
doing the cleanup required when move_in_progress is true.

This can lead to races in create_irq() if the function picks an irq
desc that's been marked as unused but has move_in_progress set, as the
call to assign_irq_vector() in that function can then fail with
-EAGAIN.

Prevent that by only marking irq descs as unused when all the cleanup
has been done.  While there also use write_atomic() when setting
IRQ_UNUSED in _clear_irq_vector() and add a barrier in order to
prevent the setting of IRQ_UNUSED getting reordered by the compiler.

The check for move_in_progress cannot be removed from
_assign_irq_vector(), as other users (io_apic_set_pci_routing() and
ioapic_guest_write()) can still pass active irq descs to
assign_irq_vector().

Note the trace point is not moved and is now set before the irq is
marked as unused.  This is done so that the CPU mask provided in the
trace point is the one belonging to the current vector, not the old
one.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: e267d11969a40f0aec33dbf966f5a6490b205f43
master date: 2022-12-02 10:32:21 +0100
xen/arch/x86/irq.c